﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

/// <summary>
/// Summary description for Links
/// </summary>
public class LinksHandler : IHttpHandler
{
    public LinksHandler()
	{
	
	}

    #region IHttpHandler Members

    public bool IsReusable
    {
        get { return false; }
    }

    public void ProcessRequest(HttpContext context)
    {
        HttpRequest Request = context.Request;
        HttpResponse Response = context.Response;

        if ( Request.Params["g"] != null )
        {
            DataClassesDataContext dd = new DataClassesDataContext(System.Configuration.ConfigurationManager.ConnectionStrings["GeoTwitterDataConnectionString"].ConnectionString);
            var row = dd.Links.Single(p => p.ID ==  Int32.Parse(Request.Params["g"].ToString()));

            //http://maps.google.com/?ie=UTF8&ll=33.898265,-117.318406
            Response.Redirect("http://maps.google.com/?ie=UTF8&ll=" + row.lat + "," + row.lon);            
        }
    }

    #endregion
}
